package gapidt.analysis;

import gapidt.common.Locale;
import java.util.HashMap;
import java.util.Map;

public class DesignProblem<T>{
	
	protected APIDesignAnalysisResult<?> analysisResult;
	protected T subject = null;
	protected Map<String, String> templateBindings = new HashMap<String, String>();
	
	public DesignProblem(T subject){
		this.subject = subject;
	}
	
	public T getSubject() {
		return subject;
	}

	public void setSubject(T subject) {
		this.subject = subject;
	}

	public APIDesignAnalysisResult<?> getAnalysisResult() {
		return analysisResult;
	}

	public void setAnalysisResult(APIDesignAnalysisResult<?> analysisResult) {
		this.analysisResult = analysisResult;
	}

	public String getName() {
		return evalTemplate(Locale.getMessage("designProblems."+getClass().getSimpleName()+".title"));
	}
	
	public String getProblemDescription(){
		return evalTemplate(Locale.getMessage("designProblems."+getClass().getSimpleName()+".problem"));
	}
	
	public String getSolutionDescription(){
		return evalTemplate(Locale.getMessage("designProblems."+getClass().getSimpleName()+".solution"));
	}

	public void addTemplateBinding(String name, String value){
		templateBindings.put(name, value);
	}
	
	public String getTemplateBinding(String name){
		return templateBindings.get(name);
	}
	
	public String evalTemplate(String template){
		String result = new String(template);
		for(String key : templateBindings.keySet())
			result = result.replaceAll("%"+key+"%", templateBindings.get(key));
		return result;
	}
	
}
